/**
 * @author roua_troua
 */

package q10.GUI;

import q10.ArboriFunctionali;
import q10.Visitor.*;

import javax.swing.JTextField;
/**
 *
 * @author OC
 */
public class DerivareField implements Command{
    private ArboriFunctionali a;
    private JTextField textDerivare;
    private ArboriFunctionali stareA;
    private String stareText;

    public DerivareField(ArboriFunctionali a,JTextField td){
        this.a = a;
        this.textDerivare = td;
    }

    public ArboriFunctionali execute(){
        getStare();
        Visitor derivVisitor = new DerivareVisitor();
        a.acceptVisitor(derivVisitor);
        textDerivare.setText(((DerivareVisitor)derivVisitor).getRezultatDeriv());
        return a;
    }

    public ArboriFunctionali unexecute(){
        this.a = stareA;
        textDerivare.setText(stareText);
        return a;
    }

    public void getStare(){
        this.stareA = a;
        this.stareText = textDerivare.getText();
    }

    public void update(ArboriFunctionali af){
        this.a = af;
    }
}
